package cn.shyouchi.wuguanjia.android.ui.event;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.api.event.EventApi;
import cn.shyouchi.wuguanjia.android.base.BaseActivity;
import cn.shyouchi.wuguanjia.android.subscribers.ProgressSubscriber;
import cn.shyouchi.wuguanjia.android.widget.TopBar;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

public class EventManagerActivity extends BaseActivity {


    @BindView(R.id.rv_events)
    RecyclerView mRvEvents;
    List<EventEntity.ResultMessageBean> mEntities = new ArrayList<>();
    EventManagerAdapter mAdapter;
    @BindView(R.id.topBar)
    TopBar mTopBar;

    EventApi mEventApi;

    @Override
    public int initContentView() {
        return R.layout.activity_event_manager;
    }





    @Override
    public void initInjector() {
        mEventApi = new EventApi(mContext);
    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        mTopBar.setLeftIcon(R.mipmap.ic_back);
        mTopBar.setTitle(getTitle().toString());
        setSupportActionBar(mTopBar.getToolbar());
        mRvEvents.setLayoutManager(new LinearLayoutManager(mContext));
        mAdapter = new EventManagerAdapter(mEntities);
        mRvEvents.setAdapter(mAdapter);
        mEventApi.getProjectList()
                .subscribeOn(Schedulers.io())
                .map(new Func1<EventEntity, List<EventEntity.ResultMessageBean>>() {
                    @Override
                    public List<EventEntity.ResultMessageBean> call(EventEntity entity) {
                        return entity.getResultMessage();
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ProgressSubscriber<List<EventEntity.ResultMessageBean>>(mContext) {
                    @Override
                    public void onNext(List<EventEntity.ResultMessageBean> resultMessageBeen) {
                        mEntities.clear();
                        mEntities.addAll(resultMessageBeen);
                        mAdapter.notifyDataSetChanged();
                    }
                });

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }


}
